<template>
  <div class="praise">
    <div class="body">
      <div class="body-content">
        <el-card class="box-card">
          <el-collapse v-model="activeName" accordion>
            <el-collapse-item title="文章点赞信息" name="1">
              <!-- <div> -->
                <!-- <h4>文章点赞信息</h4> -->
                <ul v-if="articlePraise.length>0">
                  <li
                    v-for="(apItem,apIndex) in articlePraise"
                    :key="apIndex"
                    @mouseenter="hoverAIndex = apIndex"
                    @mouseleave="hoverAIndex = -1"
                    class="praise-li">
                    <div class="praise-li-dv">
                      <img :src="apItem.img" alt="" class="praise-li-img">
                      <div class="praise-li-title">
                        <h3 class="plnpra-nickname">{{apItem.title}}</h3>
                        <span>{{apItem.time}}</span>
                        <div  @click="cancelArticle(apItem.dataPraiseId)" class="cancelPraise" :class="{'link-item-hover':apIndex==hoverAIndex}">
                          <img src="/static/img/tubiao/取消.png" alt="" class="praise-li-tubiao">
                          <span>取消点赞</span>
                        </div>
                      </div>
                      <span class="praise-li-content" :title="apItem.content" @click="to('/details',apItem.data_id)">{{apItem.content}}</span>
                    </div>
                    <el-divider></el-divider>
                  </li>

                </ul>
                <div v-else @click="go('/home')" class="kong"><i class="iconfont icon-meiyoushuju"></i> 还没有文章点赞信息哦，快去首页看看吧</div>
              <!-- </div> -->
            </el-collapse-item>
            <el-collapse-item title="评论点赞信息" name="2">
              <ul v-if="reviewPraise.length>0">
                <li
                  v-for="(rpItem,rpIndex) in reviewPraise"
                  :key="rpIndex"
                  @mouseenter="hoverRIndex = rpIndex"
                  @mouseleave="hoverRIndex = -1"
                  class="praise-li">
                  <div class="praise-li-dv">
                    <img :src="rpItem.avatar" alt="" class="praise-li-avatar">
                    <div class="praise-li-nickname">
                      <h3 class="plnpra-nickname">{{rpItem.nickname}}</h3>
                      <span>{{rpItem.Introduction}}</span>
                      <div @click="cancelReview(rpItem.praiseMeId)" class="cancelPraise" :class="{'link-item-hover':rpIndex==hoverRIndex}">
                        <img src="/static/img/tubiao/取消.png" alt="" class="praise-li-tubiao">
                        <span>取消点赞</span>
                      </div>
                    </div>
                    <span>{{rpItem.topic_type}}</span>
                  <span :title="rpItem.content" class="praise-li-review">{{rpItem.content}}</span>
                  </div>

                  <el-divider></el-divider>
                </li>

              </ul>
              <div v-else @click="go('/messageBoard')"  class="kong"><i class="iconfont icon-meiyoushuju"></i>还没有评论点赞信息哦,快去看看有趣的评论吧</div>
            </el-collapse-item>
          </el-collapse>
        </el-card>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        reviewPraise:[],
        articlePraise:[],
        activeName:'1',
        hoverAIndex: -1, // 菜单hover索引
        hoverRIndex:-1,
        isLogin:"",
        user_id:""
      }
    },
    mounted(){
      this.getPraise();
      this.getDataPraise();
      this.isLogin = this.$store.getters.getShow;
      if(this.isLogin){
        this.user_id = this.$store.getters.getUser.user_id;
        console.log(this.user_id);
      }
    },
    methods: {
      async getPraise(){
         this.isLogin = this.$store.getters.getShow;
        if(this.isLogin){
          this.user_id = this.$store.getters.getUser.user_id;
          console.log(this.user_id);
        }
        // const {data:reviewRes} = await this.$http.get("selReviewPraise");
        let user_id = this.user_id;
        console.log(user_id);
        const {data:reviewRes} = await this.$http.post("selReviewPraise",{user_id});
        console.log(reviewRes);
        if(reviewRes.status != 200){
          this.$message.error('查询点赞情况失败');
        }else{
          this.reviewPraise = reviewRes.message;
        }

      },
      async getDataPraise(){
        let user_id = this.user_id;
        const {data:articleRes} = await this.$http.post("selArticlePraise",{user_id});
        console.log(articleRes);
        if(articleRes.status != 200){
          this.$message.error('查询点赞情况失败');
        }else{
          this.articlePraise = articleRes.message;
        }
      },
      go(path){
        this.$router.push(path)
      },
      to(path,id){
        this.$router.push({path:path,query:{id:id}})
      },
      async cancelArticle(id){
        // console.log(item);
        // let mesObj = JSON.stringify(item);
        let variate = id;
        const {data:res} = await this.$http.post("delPraiseData",{variate});
        if(res.status != 200){
          this.$message.error('取消点赞失败');
        }else{
          this.$message({
          message: '取消点赞成功',
          type: 'success'
        });
        this.getDataPraise();
        }
      },
      async cancelReview(id){
        console.log(id);
        let variate = id;
        const {data:res} = await this.$http.post("delPraiseMes",{variate});
        if(res.status != 200){
          this.$message.error('取消点赞失败');
        }else{
          this.$message({
          message: '取消点赞成功',
          type: 'success'
        });
        this.getPraise();
        }
      }
    }
  }
</script>
<style scoped>

@import url('./css/person.css');
</style>
